﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Happy.Primitive;
using Happy.Dto.CommonModel.TreeLike;
using Happy.Query;
using Happy.Query.Filters;
using Happy.Query.CommonModel.TreeLike;

namespace Happy.Application.Query.CommonModel.TreeLike
{
    /// <summary>
    /// 树形结构的查询服务。
    /// </summary>
    public abstract class TreeNodeQueryService<T, TId> : QueryService<T, TId>, ITreeNodeQueryService<T, TId>
        where T : ITreeNodeView<TId>
        where TId : struct
    {
        /// <summary>
        /// 返回孩子。
        /// </summary>
        public IEnumerable<T> Children(QueryRequest request, TId? id)
        {
            var queryArgument = request.ToQueryArgument(this.FilterDefinition);

            return Children(queryArgument, id);
        }

        /// <summary>
        /// 返回孩子。
        /// </summary>
        protected virtual IEnumerable<T> Children(QueryArgument queryArgument, TId? id)
        {
            return this.QuerySource.Children(queryArgument, id);
        }
    }

    /// <summary>
    /// 树形结构的查询服务。
    /// </summary>
    public abstract class TreeNodeQueryService<T> : TreeNodeQueryService<T, Guid>
        where T : ITreeNodeView<Guid>
    {
    }
}
